package com.li.springbootproject.service.redis;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.BoundValueOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author LiDong
 * @version 1.0.0
 * @createTime 2021/10/29
 */
@Service
public class RedisServiceImpl implements RedisService {

    private static final Logger logger = LoggerFactory.getLogger(RedisServiceImpl.class);

    @Autowired
    public RedisTemplate redisTemplate;

    @Override
    public void testOne() {
        // 增加key
        redisTemplate.boundValueOps("key1").set("zhangsan");
        redisTemplate.boundValueOps("key2").set("李四", 1, TimeUnit.MINUTES);

        BoundValueOperations key3 = redisTemplate.boundValueOps("key3");
        key3.set("王五");

        ValueOperations valueOperations = redisTemplate.opsForValue();
        valueOperations.set("key4", "hellow Key4!");
        valueOperations.set("key5", "hellow Key5!", 1, TimeUnit.MINUTES);
    }
}
